package com.elves.auth.config;


import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

public class ScopeWithDescription {
    private static final String DEFAULT_DESCRIPTION = "定制的权限";
    private static final Map<String, String> scopeDescriptions = new HashMap<>();

    static {
        scopeDescriptions.put(
                "profile",
                "验证您的身份");
        scopeDescriptions.put(
                "message.read",
                "了解您可以访问哪些权限");
        scopeDescriptions.put(
                "message.write",
                "代表您行事");
    }

    public final String scope;
    public final String description;

    ScopeWithDescription(String scope) {
        this.scope = scope;
        this.description = scopeDescriptions.getOrDefault(scope, DEFAULT_DESCRIPTION + ":" + scope);
    }

    private static Set<ScopeWithDescription> withDescription(Set<String> scopes) {
        Set<ScopeWithDescription> scopeWithDescriptions = new LinkedHashSet<>();
        for (String scope : scopes) {
            scopeWithDescriptions.add(new ScopeWithDescription(scope));

        }
        return scopeWithDescriptions;
    }
}
